/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: LambdaQueryImpl.java   2020-10-10 17-59-06
 * Author: Evan
 */
package cn.datacare.orm.query;

import cn.datacare.orm.manager.impl.SQLManager;
import cn.datacare.orm.util.kit.BeanKit;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-10-10 17-59-06
 * @since V1.0
 */
public class LambdaQueryImpl<T extends StringQuery>  extends  QueryImpl<T> implements LambdaQuery<T> {


    private LambdaQueryImpl(SQLManager sqlManager, Class<T> clazz) {
        super(sqlManager, clazz);
    }

    /**
     * 设置
     * @return   Builder<T>
     */
    public static  <T extends StringQuery>  Builder<T> builder(){
         return new Builder<>();
    }

    /***
     * 构建对象
     * @param <T>
     */
    public static class Builder<T extends StringQuery>{
        /**
         * 泛型类型
         */
        private Class<T> clazz;
        /**
         *  SQLManager
         */
        private SQLManager sqlManager;

        private Builder() {

        }

        /**
         * 设置Class<T> clazz
         * @param clazz Class
         * @return Builder<T>
         */
        public Builder clazz(Class<?> clazz){
            this.clazz= (Class<T>) clazz;
            return this;
        }

        public Builder sqlManager(SQLManager  sqlManager){
            this.sqlManager=sqlManager;
            return this;
        }

        public LambdaQueryImpl<T> build(){
            if (BeanKit.queryLambdasSupport) {
                return new LambdaQueryImpl<T>(this.sqlManager, this.clazz);
            } else {
                throw new UnsupportedOperationException("需要Java8以上");
            }
        }
    }
}
